package org.alanlau.hystrix.feign.factory;

import feign.hystrix.FallbackFactory;
import org.alanlau.hystrix.annotation.FeignFallback;
import org.alanlau.hystrix.feign.TestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 相比 Fallback ，FallbackFactory能得到具体的回退原因
 * @author alan
 * @version 1.0
 * @date 2020/9/17 0:10
 */
@FeignFallback
public class TestClientFallbackFactory implements FallbackFactory<TestClient> {
    private Logger logger = LoggerFactory.getLogger(TestClientFallbackFactory.class);

    @Override
    public TestClient create(Throwable throwable) {
        logger.error("TestClient回退：", throwable);

        return new TestClient() {
            @Override
            public String hello() {
                return "fail";
            }
        };
    }
}
